package com.study.leetcode;

import java.util.Arrays;

public class Solution_2171 {
    public long minimumRemoval(int[] beans) {
        Arrays.sort(beans);
        long sum = 0;
        for (int bean : beans) {
            sum += bean;
        }
        long ans = sum;
        int length = beans.length;
        for (int i = 0; i < length; i++) {
            ans = Math.min(ans, sum - ((long) beans[i] * (length - i)));
        }
        return ans;
    }
}
